<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/user.jsp"%>
<%@ include file="/common/message.jsp"%>
<%
    // 标记完成
    String id = input.getDesc("id", "-1");
    Integer isDone = input.getInt("is_done", 0);
    List<Arrangement> list = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("id=", id).and("partner=", token.getUid())).query().getResultObj();
    if (isEmpty(list)) {
        msg = new Message(30041, "暂无日程");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    Arrangement ag = list.get(0);
    ag.setIsDone(isDone);
    DBTools.db("basedb").modItem(ag, ag.getId());
    String team = ag.getTeam();
    List<Arrangement> ags = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("team=", team)).query().getResultObj();
    // 判断是否已经全部确认
    boolean allDone = true;
    for (int i = 0; i < ags.size(); i++) {
        ag = ags.get(i);
        if (ag.getIsDone() == 0) {
            allDone = false;
            break;
        }
    }
    if (allDone) {
        Information info = new Information();
        info.setOid(ag.getId()+"");
        info.setHospital(ag.getHospital());
        info.setTitle("日程通知");
        info.setSumary("日程");
        User user = userByUid(ag.getUid());
        info.setContent(user.getName() + "您好, 您创建的日程已全部确认。\n内容:"+ag.getTitle()+"\n日期:"+ag.getStart());
        info.setCategory(4);
        createMsg(info, ag.getUid());
    }
    msg.put("data", isDone);
    Tools.encryptPrint(out, msg);
%>
